package com.itheima.aimobile.controller;

import com.itheima.aimobile.domain.vo.MessageVO;
import com.itheima.aimobile.service.IChatHistoryService;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ai/history")
public class ChatHistoryController {
    //不区分会话历史与某个会话的内容只根据会话id保存相应的聊天记录
    @Autowired
    private ChatMemoryRepository chatMemoryRepository;
    //将会话记录表与相对应的会话内容分开来保存
    @Autowired
    private IChatHistoryService chatHistoryService;
    @Autowired
    private ChatMemory chatMemory;
    @GetMapping("/{type}")
    public List<String> getHistoryList(@PathVariable String type){
        return chatHistoryService.getChatIds(type,null);
    }
    @GetMapping("/{type}/{chatId}")
    public List<MessageVO> getChatId(@PathVariable String type, @PathVariable String chatId){
        List<Message> messageList = chatMemory.get(chatId);
        return messageList.stream().map(MessageVO::new).toList();
    }


}
